package com.smart.home.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 统一返回结果 封装类 接口serializable是为了序列化便于传输
 */
@Data
public class Result<T> implements Serializable {

    private int code;
    private String msg;
    private T data;

    public static <T> Result<T> success(T object){
        Result<T> result = new Result<T>();
        result.data = object;
        result.code = 1;
        return result;
    }

    public static <T> Result<T>  success(){
        Result<T> result = new Result<T>();
        result.code = 1;
        return result;
    }

    public static <T> Result<T>  error(String msg){
        Result<T> result = new Result<T>();
        result.code = 1;
        result.msg = msg;
        return result;
    }
}
